/*-
 * IntValue.java
 *
 * $LastChangedBy: stein $
 * $LastChangedRevision: 37 $
 * $LastChangedDate: 2006-11-30 23:06:29 +0000 (Thu, 30 Nov 2006) $
 * $HeadURL: svn://localhost/SMS/src/com/googlecode/attention/sms/pdu/UDHI.java $
 *
 * Copyright (c) 2007, Stein Gunnar Bakkeby
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Stein Gunnar Bakkeby nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.googlecode.attention.util;

/**
 * A class that holds an integer.
 *
 * @author Stein Gunnar Bakkeby
 */
public abstract class IntValue {
  /* Field values */
  protected int value;

  /**
   * Constructor, creates a new IntValue with a value of 0.
   */
  public IntValue() {
    this(0);
  }
  
  /**
   * Constructor, creates the value holder.
   * 
   * @param hex The hexadecimal value
   */
  public IntValue(final String hex) {
    this(Convert.hexToInt(hex));
  }
  
  /**
   * Constructor, creates the value holder.
   * 
   * @param value The value to hold
   * @see #setValue(int)
   */
  public IntValue(final int value) {
    setValue(value);
  }

  /**
   * This will set the value and throw an exception if not a valid argument.
   * 
   * @param value The value to hold
   */
  public void setValue(final int value) {
    this.value = value;
  }

  /**
   * This will return the value of this value holder.
   * 
   * @return The value, see static field values
   */
  public int getValue() {
    return value;
  }
  
  /**
   * This will return the hex (string) of the value contained within this
   * value holder.
   * 
   * @return Hex in String form
   */
  public String getHex() {
    return Convert.intToHex(value, 2);
  }
  
  /**
   * This will return the binary string of the value contained within this
   * value holder.
   * 
   * @return Binary string in String form
   */
  public String getBinaryString() {
    return Convert.intToBin(value, 8);
  }
  
  @Override
  public boolean equals(final Object another) {
    if (another instanceof IntValue) {
      return value == ((IntValue)another).value;
    }
    return false;
  }
}